#ifndef J3DGRAPH_BTP_TPT1_HEADER
#define J3DGRAPH_BTP_TPT1_HEADER

// this header needs
#include <stdio.h>
#include "../J3DGRAPH.h"

// TPT1 section constants
#define J3DGRAPH_BTP_TPT1_POS 0

// j3dgraph_btp_tpt1_err_cd enum
// enum with the possible codes a TPT1 section will present while analizing it
// (1) means that the error can be checked with a TPT1 section from a BTP only
// (2) means that the error comes from a check agaisnt BMD/BDL MAT3 and TEX1 sections
// errors codes are organized so fatal errors have less magnitude than the soft errors
typedef enum
{
  J3DGRAPH_BTP_TPT1_ERR_INV_STRUCT,         // (1) j3dgraph struct ptr is NULL/empty
  J3DGRAPH_BTP_TPT1_ERR_HEADER,             // (1) section header is inconsistent
  J3DGRAPH_BTP_TPT1_ERR_TPT1_OFFSET,        // (1) stored tpt1 section offset is not the usual one
  J3DGRAPH_BTP_TPT1_ERR_TEX_TB_OFFSET,      // (1) stored texture swap table offset is not the correct one
  J3DGRAPH_BTP_TPT1_ERR_MAT_STR_TB_OFFSET,  // (1) stored material name table offset is not the correct one
  J3DGRAPH_BTP_TPT1_ERR_MAT_ANIM_DT_POS,    // (1) animation data for a material goes outside the tex swap table
  J3DGRAPH_BTP_TPT1_ERR_UNK_2,              // (1) unknown 2 is not the usual one
  J3DGRAPH_BTP_TPT1_ERR_TEX_TB_LENGTH,      // (1) the texture swap table length is not the correct one
  J3DGRAPH_BTP_TPT1_ERR_MAT_STR_TB_START,   // (1) the material name table does not start with the correct value
  J3DGRAPH_BTP_TPT1_ERR_INV_STR_TB,         // (1) section's string table is invalid 
  J3DGRAPH_BTP_TPT1_ERR_INV_TEX_INDEX,      // (2) illegal texture index value in the texture swap table 
  J3DGRAPH_BTP_TPT1_ERR_MAT_CNT_OVERFLOW,   // (2) more materials on the tpt1 than on the mat3 section
  J3DGRAPH_BTP_TPT1_ERR_INV_MAT,            // (2) section contains a material not found on the mat3 section
  
  J3DGRAPH_BTP_TPT1_ERR_NO_ERR,             // errors below this (in value) are fatal, above or equal are safe  
  
  J3DGRAPH_BTP_TPT1_ERR_LOOP_MD,            // (1) loop mode is outside the 0-4 range
  J3DGRAPH_BTP_TPT1_ERR_UNK_1,              // (1) unknown 1 is not the usual one
  J3DGRAPH_BTP_TPT1_ERR_MAT_IND_TB_OFFSET,  // (1) stored material position table offset is not the correct one
  J3DGRAPH_BTP_TPT1_ERR_MAT_ANIM_LENGTH,    // (1) individual material animation length is set to 0
  J3DGRAPH_BTP_TPT1_ERR_UNK_3,              // (1) unknown 3 is not the usual one
  J3DGRAPH_BTP_TPT1_ERR_DIF_ENDIAN_MODEL,   // (2) section endian is different than of the mat3 and tex1 sections
  J3DGRAPH_BTP_TPT1_ERR_MAT_IND_TB,         // (2) material index table contains invalid indexes for a material
} j3dgraph_btp_tpt1_err_cd;

// BMD TPT1 section (complete)
typedef struct
{
  // my additions
  char * PATH;                        // file path
  ENDIAN_T ENDIAN;                    // endian
  j3dgraph_btp_tpt1_err_cd ERR_CD;    // error code
  // actual structure
  byte * START;                       // 00 char[4]
  byte * SIZE;                        // 01 uint32
  byte * LOOP_MD;                     // 02 uint8 
  byte * UNK_1;                       // 03 1 byte
  byte * ANIM_LENGTH;                 // 04 uint16
  byte * ANIM_MAT_CNT;                // 05 uint16
  byte * TEX_SWP_TB_LENGTH;           // 06 uint16
  byte * TPT1_OFFSET;                 // 07 uint32
  byte * TEX_SWP_TB_OFFSET;           // 08 uint32
  byte * ANIM_MAT_IND_TB_OFFSET;      // 09 uint32
  byte * ANIM_MAT_STR_TB_OFFSET;      // 10 uint32
  byte * ANIM_TB;                     // 11 ANIM_MAT_COUNT * 8 bytes
  byte * TEX_SWP_TB;                  // 12 ANIM_MAT_COUNT * 2 bytes
  byte * PAD_1;                       // 13 ?? (4 multiple address)
  byte * ANIM_MAT_IND_TB;             // 14 ANIM_MAT_COUNT * 2 bytes
  byte * PAD_2;                       // 15 ?? (4 multiple address)  
  j3dgraph_str_tb * ANIM_MAT_STR_TB;  // 16 ??  
  byte * PAD_3;                       // 17 ?? (32 multiple address)
} j3dgraph_btp_tpt1;

// functions to check the information on the BTP TPT1 section
j3dgraph_btp_tpt1_err_cd check_j3dgraph_btp_tpt1(j3dgraph * file);

// append/remove/print the j3dgraph_btp_tpt1
// structure to an incomplete j3dgraph structure
j3dgraph_btp_tpt1 * append_j3dgraph_btp_tpt1(j3dgraph * file);
void remove_j3dgraph_btp_tpt1(j3dgraph * file);
void print_j3dgraph_btp_tpt1(j3dgraph_btp_tpt1 * tpt1);

// specific functions
j3dgraph_btp_tpt1_err_cd check_j3dgraph_btp_tpt1_agst_bmd_bdl_mat3_tex1(j3dgraph_btp_tpt1 * tpt1, j3dgraph_bmd_mat3 * mat3, j3dgraph_bmd_tex1 * tex1);
void write_j3dgraph_btp_tpt1_csv(j3dgraph * btp);

#include "TPT1.c"

#endif // J3DGRAPH_BTP_TPT1_HEADER
